package com.slt.android.screenshot;

import android.app.IntentService;
import android.content.Intent;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.util.Log;

import java.io.File;

/**
 * Created by dp on 2018/5/9.
 */

public class ShotService  extends IntentService {

    public static final String TAG = "ShotService";


    public ShotService() {
        super("ShotService");
    }
    /**
     * Creates an IntentService.  Invoked by your subclass's constructor.
     *
     * @param name Used to name the worker thread, important only for debugging.
     */
    public ShotService(String name) {
        super("ShotService");
    }


    @Override
    public void onCreate() {
        Log.e(TAG, "onCreate");
        super.onCreate();
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        File dir = new File("/sdcard/" , "mysshhoottss");
        if(!dir.exists()){
            dir.mkdirs();
        }

        File dir2 = new File(dir.getAbsolutePath() , "tmp");
        if(!dir2.exists()){
            dir2.mkdirs();
        }

        while (!getBooleanFlag()){
            ScreentShotUtil.getInstance().takeScreenshot(this , dir2.getAbsolutePath());
            try {
                Thread.sleep(1000 * 10 );
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    private boolean getBooleanFlag() {
        boolean b = AbSharedUtil.getBoolean(this , "exitFlag" , false);
        return b;
    }

}
